<template>
<div :class="[$style.container]" @keyup.enter="onConfirm">
<el-dialog title="编辑备注" :visible.sync="actualVisible" width="30%">
  <el-form size="small" label-position="top" :rules="rules" :model="form" @submit.native.prevent="" ref="fm">
    <el-form-item prop="remark">
      <el-input type="textarea" v-model="form.remark" placeholder="请填写备注" clearable ref="nameInput" maxlength="50" show-word-limit></el-input>
    </el-form-item>
  </el-form>
  <span slot="footer">
    <el-button size="small" :disabled="submitting" @click="onCancel" class="px-5">取 消</el-button>
    <el-button size="small" type="primary" @click="onConfirm" :loading="submitting" class="px-5">确 定</el-button>
  </span>
</el-dialog>
</div>
</template>

<script lang="ts">

import { ModalMixins } from '@/mixins'
import { Vue, Component, Prop, Emit, Ref } from 'vue-property-decorator'
import { mixins } from 'vue-class-component'
import { remark } from '@/api/doc'

@Component
export default class DocRemarkModal extends mixins(ModalMixins) {
  @Ref() fm!: any

  data: any = null

  form = {
    remark: ''
  }

  rules = {
  }

  get disabled () {
    return this.data?.remark === this.form.remark
  }

  open (data: any) {
    this.data = data
    this.$nextTick(() => {
      if (this.fm) this.fm.resetFields()
      this.form.remark = data?.remark || ''
      const input = this.$refs.nameInput as any
      if (input) input.focus()
    })
    return this.init()
  }

  onCancel () {
    this.cancel()
  }

  onConfirm () {
    this.fm.validate().then((valid: boolean) => {
      if (!valid) return
      this.submitting = true
      remark(this.data?.id, this.form.remark).then((data) => {
        this.complete(data)
      }).finally(() => {
        this.submitting = false
      })
    })
  }
}
</script>

<style lang="scss" module>
@import "~@/styles/vars.scss";

.container {

}

.content {
  height: calc(100vh - 15vh - 50px - 54px - 40px - 62px - 80px);
}

</style>
